package com.springboot.demo.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.springboot.demo.service.CommonService;
import com.springboot.demo.utils.ResponseUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author wubc683
 * @desc
 * @date 2021-12-22 17:55
 */
@RestController
@Api(tags = "公共接口")
@Validated
public class CommonController {
    @Autowired
    ResponseUtils responseUtils;
    @Autowired
    CommonService commonService;

    @GetMapping("/common/provinces")
    @ApiOperation(value = "获取所有省份")
    @ApiOperationSupport(order = 10)
    public ResponseUtils<Map<Integer,Object>> getAllProvinces() {
        Map<Integer, Object> allProvinces = commonService.getAllProvinces();
        return responseUtils.buildSuccessResponse(allProvinces);
    }

    @GetMapping("/common/province/{num}/cities")
    @ApiOperation(value = "获取一个省的所有市")
    @ApiOperationSupport(order = 20)
    public ResponseUtils<Map<Integer,String>> getAllCitiesByProvinceNum(@PathVariable("num") @ApiParam(
            "省份的序号，从获取省份接口获取") Integer num) {
        Map<Integer, String> allCitiesByProvinceNum = commonService.getAllCitiesByProvinceNum(num);
        return responseUtils.buildSuccessResponse(allCitiesByProvinceNum);
    }

    @GetMapping("/common/industry/type")
    @ApiOperation(value = "获取行业类型")
    @ApiOperationSupport(order = 20)
    public ResponseUtils<Map<Integer,String>> getAllIndustryType() {
        Map<Integer, String> allIndustryType = commonService.getAllIndustryType();
        return responseUtils.buildSuccessResponse(allIndustryType);
    }
}
